<extend name="Public/base"/>

<block name="body">
    <link rel="stylesheet" type="text/css" href="__CSS__/goods.css" media="all">
    <div class="main-title">
        <h2>商品管理</h2>
    </div>

    <div class="cf">
        <a class="btn" href="{:U('add')}">新 增</a>
        <button class="btn ajax-post" url="{:U('checked',array('checked'=>'1'))}" target-form="ids">上 架</button>
        <button class="btn ajax-post" url="{:U('checked',array('checked'=>'0'))}" target-form="ids">下 架</button>
        <button class="btn ajax-post confirm" url="{:U('del')}" target-form="ids">删 除</button>
        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <form action="{:U('Goods/index')}" method="post">
                    <select id="fpid" name="fpid" style="float:left;margin-right: 5px;">
                        <option value="">请选择</option>
                        <volist name="fcaty" id="fcy">
                            <option value="{$fcy.id}">{$fcy.title}</option>
                        </volist>
                    </select>

                    <select id="spid" name="spid" style="float:left;margin-right: 5px;">
                        <option value="">请选择</option>
                    </select>

                    <select id="tpid" name="tpid" style="float:left;margin-right: 5px;">
                        <option value="">请选择</option>
                    </select>

                    <input type="text" name="name" class="text" value="" placeholder="请输入商品名称">
                    <input type="submit" value="搜索">
                </form>
            </div>
        </div>
    </div>

    <div class="data-table table-striped">
        <table>
            <thead>
                <tr>
                    <th class="row-selected">
                        <input class="checkbox check-all" type="checkbox">
                    </th>
                    <th>ID</th>
                    <th>商品标题</th>
                    <th>编号</th>
                    <th>价格</th>
                    <th>已售</th>
                    <th>库存</th>
                    <th>销量</th>
                    <th>收藏量</th>
                    <th>浏览量</th>
                    <th>上下架</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <notempty name="list">
                <volist name="list" id="info">
                    <tr>
                        <td><input class="ids row-selected" type="checkbox" name="id[]" value="{$info.id}"></td>
                        <td>{$info.id}</td>
                        <td><a href="{:U('edit?id='.$info['id'])}">{$info.name}</a></td>
                        <td>{$info.num}</td>
                        <td>{$info.price}</td>
                        <td>{$info.sales}</td>
                        <td>{$info.stock}</td>
                        <td>{$info.sales}</td>
                        <td>{$info.collects}</td>
                        <td>{$info.clicks}</td>
                        <td>
                            <?php if($info['checked']==1){?>
                                <a class="ajax-get" title="审核" href="<?php echo U('checked?id='.$info['id'].'&checked=0'); ?>">√</a>
                            <?php }else{ ?>
                                <a class="ajax-get red" title="审核" href="<?php echo U('checked?id='.$info['id'].'&checked=1'); ?>">×</a>
                            <?php }?>
                        </td>
                        <td>
                            <a title="编辑" href="{:U('edit?id='.$info['id'])}">编辑</a>
                            <a class="confirm ajax-get" title="删除" href="{:U('del?id='.$info['id'])}">删除</a>
                            <a href="javascript:;">预览</a>
                        </td>
                    </tr>
                </volist>
                <else/>
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容! </td>
                </notempty>
            </tbody>
        </table>
        <!-- 分页 -->
        <div class="page">
            {$page}
        </div>
    </div>
</block>

<block name="script">
<script type="text/javascript">
$(function(){
    //选择一级分类
    $('#fpid').change(function(){
        $('#spid').html('<option value="">请选择</option>');
        $('#tpid').html('<option value="">请选择</option>');
        //属性值，规格值做对应的改变
        var pid = $(this).val();
        if(pid){
            //ajax获取子分类
            getSub('#spid', pid);
        }

    });

    //选择二级分类
    $('#spid').change(function(){
        $('#tpid').html('<option value="">请选择</option>');
        //属性值，规格值做对应的改变
        var pid = $(this).val();
        if(pid){
            //ajax获取子分类
            getSub('#tpid', pid);
        }

    });


    //获取子分类ajax
    function getSub(c_id, pid){
        //ajax获取子分类
        $.ajax({
            url : '{:U("Goods/getSubCategory")}',
            data : {"pid":pid},
            dataType : 'JSON',
            type : 'POST',
            success : function(ret){
                if(ret.status==1){
                    var info = ret.info;
                    var len = info.length;
                    var str = '<option value="">请选择</option>';
                    for(i=0; i<len; i++){
                        str += '<option value="' + info[i]['id'] + '">' + info[i]['title'] + '</option>';
                    }
                    $(c_id).html(str);
                }
            }
        });
    }

    highlight_subnav('{:U('Goods/index')}');
});
</script>
</block>